package com.baizhi.bzmall.admin.controller;


import com.baizhi.bzmall.admin.service.IBzCategoryService;
import com.baizhi.bzmall.common.vo.ResultEntity;
import com.baizhi.bzmall.entity.BzCategory;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品属性; InnoDB free: 11264 kB 前端控制器
 * </p>
 *
 * @author zhengg
 * @since 202-18
 */
@RestController
@RequestMapping("/bzCategory")
public class BzCategoryController {
    @Autowired
    private IBzCategoryService categoryService;
    @GetMapping
    public ResultEntity selectFirstCategory(){
        QueryWrapper<BzCategory> wrapper= new QueryWrapper<>();
        wrapper.eq("category_level",1);
        List<BzCategory> list = categoryService.list(wrapper);
        return ResultEntity.ok(list);
    }
    @GetMapping("/childrenCategory/{pid}")
    public ResultEntity selectChildrenCategory(@PathVariable("pid") int pid){
        QueryWrapper<BzCategory> wrapper= new QueryWrapper<>();
        wrapper.eq("parent_id",pid);
        List<BzCategory> list = categoryService.list(wrapper);
        return ResultEntity.ok(list);
    }
    @GetMapping("/tree")
    public ResultEntity selectAllLevelCategory(){
        List<BzCategory> bzCategories = categoryService.selectAllLevelCategory();
        return ResultEntity.ok(bzCategories);
    }
}

